import { Alert, Link, TextField } from '@aws-amplify/ui-react';
import { TextFieldDemo } from './demo';
import {
DefaultRequiredTextFieldExample,
DefaultTextAreaExample,
DefaultTextFieldExample,
RequiredTextFieldExample,
TextAreaMaxLengthExample,
TextAreaResizableExample,
TextAreaRowsExample,
TextAreaSizeExample,
TextFieldAccessibilityExample,
TextFieldDescriptiveTextExample,
TextFieldEventHandlersExample,
TextFieldInnerComponentsExample,
TextFieldOuterAndInnerComponentsExample,
TextFieldOuterComponentsExample,
TextFieldSizeExample,
TextFieldStatesExample,
TextFieldStylePropsExample,
TextFieldThemeExample,
TextFieldValidationErrorExample,
TextFieldVariationExample,
} from './examples';
import { Example, ExampleCode } from '@/components/Example';
import { Fragment } from '@/components/Fragment';
import { ComponentClassTable } from '@/components/ComponentClassTable';
import StandardHTMLAttributes from '@/components/StandardHTMLAttributes.mdx';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import ThemeExample from '@/components/ThemeExample.mdx';
## Demo
## Usage
Import the `TextField` component and styles and provide a `label` for accessibility/usability.
```jsx file=./examples/DefaultTextFieldExample.tsx
```
### Accessibility / Label behavior
{() => import('./../shared/formFieldAccessibility.mdx')}
```jsx file=./examples/TextFieldAccessibilityExample.tsx
```
### Sizes
TextField sizes are designed to match styling of other field components such as Buttons. There are three sizes: small, (default), and large.
```jsx file=./examples/TextFieldSizeExample.tsx
```
### Variations
There are two variation styles available: default and `quiet`.
```jsx file=./examples/TextFieldVariationExample.tsx
```
### Outer components
Compose field components such as `Button` and `Select` at the start or end of an TextField input using the `outerStartComponent` or `outerEndComponent` props.
```jsx file=./examples/TextFieldOuterComponentsExample.tsx
```
### Inner components (icons)
Compose `FieldGroupIcon` or `FieldGroupIconButton` components inside TextField input using innerStartComponent and innerEndComponent.
To create an interactive icon button, use the `FieldGroupIconButton` component. To add an icon that's not interactive, use `FieldGroupIcon` component.
Note: When clicked, `FieldGroupIcon` will focus the field, whereas the `FieldGroupIconButton` will trigger its `onClick` event.
```jsx file=./examples/TextFieldInnerComponentsExample.tsx
```
_You can also both inner and outer components together_
```jsx file=./examples/TextFieldOuterAndInnerComponentsExample.tsx
```
### Descriptive text
To provide additional descriptive text of requirements of the field, use the `descriptiveText` field:
```jsx file=./examples/TextFieldDescriptiveTextExample.tsx
```
### States
The available TextField states include `isDisabled` and `isReadOnly`. A disabled field will be not be focusable not mutable and will not be submitted with form data. A readonly field cannot be edited by the user.
```jsx file=./examples/TextFieldStatesExample.tsx
```
### Required fields
Use the `isRequired` prop to specify a required field.
```jsx file=./examples/DefaultRequiredTextFieldExample.tsx
```
There is no default styling for required fields. Customize the `label` or `descriptiveText` to instruct the form user of the required field.
```jsx file=./examples/RequiredTextFieldExample.tsx
```
### Validation error styling
Use the `hasError` and `errorMessage` props to mark a TextField as having a validation error.
```jsx file=./examples/TextFieldValidationErrorExample.tsx
```
### Event handlers
TextField provides several event handlers: `onSelect`, `onInput`, `onChange`, `onCopy`, `onPaste`, and `onCut`. Open the console to interact with the demo below.
```jsx file=./examples/TextFieldEventHandlersExample.tsx
```
```jsx
```
## CSS Styling
```tsx file=./examples/TextFieldThemeExample.tsx
```
### Target classes
### Global styling
To override styling on all TextField primitives, you can set the Amplify CSS variables with the built-in `.amplify-textfield` class.
```css
/* styles.css */
.amplify-textfield {
--amplify-components-fieldcontrol-border-color: rebeccapurple;
}
```
### Local styling
To override styling on a specific TextField, you can use a class selector or style props.
_Using a class selector:_
```css
/* styles.css */
.custom-textfield-class .amplify-input {
border-radius: 0;
}
```
_Using style props:_
All style props will be applied to the [`Flex`](flex) wrapper of the `TextField`. To style the `input` of the `TextField`, you can pass a `inputStyles` prop with the style props you want to apply to the input.
```jsx file=./examples/TextFieldStylePropsExample.tsx
```